﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using Dsl.Ped.AddIn.Java.Generated;
using Dsl.Ped.Common.Commands;
using Dsl.Ped.Framework.Common;

namespace Dsl.Ped.AddIn.Java.Projections.ClassTextProjection
{
    /// <summary>
    /// Interaction logic for StringView.xaml
    /// </summary>
    public partial class ClassTextProjection : IProjection
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="parentObject">The class object</param>
        /// <param name="projectiveContent">Content to be projected inside the class</param>
        /// <param name="enterKeyOptions">Key options and their appropriate commands to be displayed on Enter</param>
        /// <param name="backKeyAction">Key action to be executed when the user press Bakspace</param>
        public ClassTextProjection(Class parentObject, IProjective projectiveContent, List<IMenuCommand> enterKeyOptions, Action backKeyAction)
        {
            InitializeComponent();

            // Instantiate the model of the projection
            this.DataContext = new ClassTextProjectionViewModel(projectiveContent, enterKeyOptions, backKeyAction);
            
            // Initialize the projection, bindings, etc..
            initializeProjection(parentObject, projectiveContent);
        }

        /// <summary>
        /// Initialize the projection
        /// </summary>
        /// <param name="parentObject">The class object</param>
        /// <param name="projectiveContent">The content to be projected inside the class</param>
        private void initializeProjection(Class parentObject, IProjective projectiveContent)
        {
            if (parentObject != null)
            {
                // Set the binding of the class name
                Binding nameBinding = new Binding("name");
                nameBinding.Source = parentObject;
                nameBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                nameBinding.ValidatesOnDataErrors = true;
                nameBinding.NotifyOnValidationError = true;
                nameTxtBox.SetBinding(TextBox.TextProperty, nameBinding);                

                // Set the binding of the superclass name
                Binding superclassBinding = new Binding("superclass");
                superclassBinding.Source = parentObject;
                superclassBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                superclassBinding.ValidatesOnDataErrors = true;
                superclassBinding.NotifyOnValidationError = true;
                superclassTxtBox.SetBinding(TextBox.TextProperty, superclassBinding);

                // Set the binding of the class content             
           /*     Binding classContentBinding = new Binding();
                classContentBinding.Source = projectiveContent;
                classContentBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                classContent.SetBinding(ProjectiveObjectUserControl.ProjectiveObjectProperty, classContentBinding);*/
            }
        }

        public FrameworkElement View
        {
            get { return this; }
        }
    }
}
